package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TPosition;
import com.ruoyi.system.service.ITPositionService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 职位信息Controller
 * 
 * @author 徐国洋
 * @date 2025-02-23
 */
@RestController
@RequestMapping("/system/position")
public class TPositionController extends BaseController
{
    @Autowired
    private ITPositionService tPositionService;

    /**
     * 查询职位信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:position:list')")
    @GetMapping("/list")
    public TableDataInfo list(TPosition tPosition)
    {
        startPage();
        List<TPosition> list = tPositionService.selectTPositionList(tPosition);
        return getDataTable(list);
    }
    @PreAuthorize("@ss.hasPermi('system:position:listAll')")
    @GetMapping("/listAll")
    public TableDataInfo listAll()
    {
        TPosition tPosition = new TPosition();
        List<TPosition> list = tPositionService.selectTPositionList(tPosition);
        return getDataTable(list);
    }
    /**
     * 导出职位信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:position:export')")
    @Log(title = "职位信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TPosition tPosition)
    {
        List<TPosition> list = tPositionService.selectTPositionList(tPosition);
        ExcelUtil<TPosition> util = new ExcelUtil<TPosition>(TPosition.class);
        util.exportExcel(response, list, "职位信息数据");
    }

    /**
     * 获取职位信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:position:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tPositionService.selectTPositionById(id));
    }

    /**
     * 新增职位信息
     */
    @PreAuthorize("@ss.hasPermi('system:position:add')")
    @Log(title = "职位信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TPosition tPosition)
    {
        return toAjax(tPositionService.insertTPosition(tPosition));
    }

    /**
     * 修改职位信息
     */
    @PreAuthorize("@ss.hasPermi('system:position:edit')")
    @Log(title = "职位信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TPosition tPosition)
    {
        return toAjax(tPositionService.updateTPosition(tPosition));
    }

    /**
     * 删除职位信息
     */
    @PreAuthorize("@ss.hasPermi('system:position:remove')")
    @Log(title = "职位信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tPositionService.deleteTPositionByIds(ids));
    }
}
